package com.woniuxy.platform.core.controller;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.platform.core.model.CarGood;
import com.woniuxy.platform.core.service.CarGoodService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gmx
 * @since 2021-07-12
 */
@RestController
@RequestMapping("carGood")
public class CarGoodController {
    @Resource
    private CarGoodService goodService;
    /**
     * Description : 查询所有商品
     * ChangeLog : 1. 创建 (2021/7/12 9:54 [fulang]);
     * @param startpage
     * @param pagesize
     * @return com.github.pagehelper.PageInfo<com.woniuxy.platform.core.model.CarGood>
    */
    @GetMapping("list")
    public PageInfo<CarGood> list(@PathVariable int startpage, @PathVariable int pagesize){
        PageHelper.startPage(startpage,pagesize);
        List<CarGood> list = goodService.list();
        Page page = (Page) list;
        PageInfo<CarGood> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }
    /**
     * Description : 删除商品
     * ChangeLog : 1. 创建 (2021/7/12 9:56 [fulang]);
     * @param id
     * @return boolean
    */
    @DeleteMapping("delete/{id}")
    public boolean delete(@PathVariable Integer id){
        boolean b = goodService.removeById(id);
        return b;
    }
    /**
     * Description : 推荐商品,修改商品信息
     * ChangeLog : 1. 创建 (2021/7/12 10:08 [fulang]);
     * @param carGood
     * @return int
    */
    @RequestMapping("update")
    public int update(@RequestBody CarGood carGood){
        int i = goodService.updateAll(carGood);
        return i;
    }/**
     * Description : 增加商品
     * ChangeLog : 1. 创建 (2021/7/12 10:11 [fulang]);
     * @param carGood
     * @return int
    */
    @RequestMapping("insert")
    public int insert(@RequestBody CarGood carGood){
        int insert = goodService.insert(carGood);
        return insert;
    }
}

